﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Xml;
using System.Data;

namespace ViecLam
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindGridViewLstEnrollInformation();
            BindGridViewLstMajor();
        }

        private void BindGridViewLstEnrollInformation()
        {
            string strRequest = "http://localhost:8080/ViecLamService/ListEnrolls.rss";
            HttpWebRequest request = (HttpWebRequest)(WebRequest.Create(strRequest));
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader streamReader = new StreamReader(response.GetResponseStream());

            // string xml
            string xmlData = streamReader.ReadToEnd();

            XmlDSLstEnrollInfor.Data = xmlData;

            gridViewLstEnrolls.DataSource = XmlDSLstEnrollInfor;
            gridViewLstEnrolls.DataBind();
        }

        private void BindGridViewLstMajor()
        {
            string strRequest = "http://localhost:8080/ViecLamService/ListMajors.rss";
            HttpWebRequest request = (HttpWebRequest)(WebRequest.Create(strRequest));
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader streamReader = new StreamReader(response.GetResponseStream());

            // string xml
            string xmlData = streamReader.ReadToEnd();

            XmlDSLstMajor.Data = xmlData;

            gridViewLstMajor.DataSource = XmlDSLstMajor;
            gridViewLstMajor.DataBind();
        }

        protected void lnkBtnEnrName_Click(object sender, EventArgs e)
        {
            LinkButton lnkBtnEnrName = sender as LinkButton;
            
            Response.Redirect("ChiTietTD.aspx?id=" + lnkBtnEnrName.CommandArgument);
        }

        protected void lnkBtnCompanyName_Click(object sender, EventArgs e)
        {
            LinkButton lnkBtnCompanyName = sender as LinkButton;

            Response.Redirect(lnkBtnCompanyName.CommandArgument);
        }

        protected void lnkBtnMajorName_Click(object sender, EventArgs e)
        {
            LinkButton lnkBtnMajorName = sender as LinkButton;

            Response.Redirect("DanhSachTuyenDungTheoNganh.aspx?id=" + lnkBtnMajorName.CommandArgument);
        }

        protected void gridViewLstEnrolls_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridViewLstEnrolls.PageIndex = e.NewPageIndex;
            BindGridViewLstEnrollInformation();
        }

        protected void gridViewLstMajor_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridViewLstMajor.PageIndex = e.NewPageIndex;
            BindGridViewLstMajor();
        }
    }
}